<template>
  <div>
    <el-form ref="form" :model="form" label-width="85px">
      <el-form-item label="会员电话:" prop="phone">
        {{form.phone}}
      </el-form-item>
      <el-col :span="12">
        <el-form-item label="会员姓名:" prop="name">
          {{form.name}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="账户余额:" prop="phone">
          <span class="money">{{form.money}}</span>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="储值余额:" prop="storedMoney">
          {{form.storedMoney}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="赠送余额:" prop="sendMoney">
          <span class="money">{{form.sendMoney}}</span>
        </el-form-item>
      </el-col>
      <el-form-item label="退款金额:" prop="reMoney">
        <el-input v-model="form.reMoney" type="number" placeholder="请输入退款金额"/>
      </el-form-item>
      <el-form-item label="备注:" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入备注"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="submitOnlyForm">确 定</el-button>

    </div>
  </div>
</template>

<script>
  import {refundMoney} from "@/api/mahjong/record";
  export default {
    name: "",
    props: {
      details: {}
    },
    data() {

      return {
        form: {}

      }
    },
    created() {
      this.form = this.details;
      console.log(this.form);
    },
    methods: {

      cancel() {
        this.$emit('update:close', false)
      },
      submitOnlyForm() {
        console.log(this.form.reMoney)
        if (!(this.form.reMoney)) {
          this.$message({
            message: '退款金额不允许为空',
            type: 'error'
          });
          return
        }
        let flag = parseFloat(this.form.reMoney) - parseFloat(this.form.storedMoney);
        if (flag > 0) {
          this.$message({
            message: '退款金额不允许大于储值金额',
            type: 'error'
          });
          return
        }

        refundMoney( this.form.id ,this.form.reMoney,this.form.remark).then(response => {
          if(response.code==200){
            this.form.money=undefined;
            this.form.storeMoney=undefined;
            this.form.sendMoney=undefined;
            this.form.reMoney=undefined;
            this.form.remark=undefined;
            this.$emit('update:close', false);
            this.$emit('goLoadMember');

            this.$message({
              message: '退款成功，账户余额30',
              type: 'success'
            });
          }

        });


      }
    }
  };
</script>

<style scoped rel="stylesheet/scss" lang="scss">
  .dialog-footer {
    text-align: right;
  }

  .money {
    color: #9F8350;
  }
</style>
